#!/bin/bash
set -e

. _common
fs="imager"
ptlfs="../src/partclone.imager"
dd_count=$((normal_size/2))

echo -e "partclone.imager test"
echo -e "====================\n"
echo -e "create raw file $raw and save as partclone image file\n"
_ptlbreak
[ -f $raw ] && rm $raw
echo -e "    dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count\n"
dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count

echo -e "\nclone $raw to $img\n"
[ -f $img ] && rm $img
echo -e "    $ptlfs -d -c -s $raw -O $img -F -L $logfile\n"
_ptlbreak
$ptlfs -d -c -s $raw -O $img -F -L $logfile
_check_return_code


echo -e "\ncreate raw file $raw for restore\n"
_ptlbreak
[ -f $raw ] && rm $raw
echo -e "    dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count\n"
dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count

echo -e "\nrestore $img to $raw\n"
echo -e "    $ptlrestore -s $img -O $raw -C -F -L $logfile\n"
_ptlbreak
$ptlrestore -s $img -O $raw -C -F -L $logfile
_check_return_code

echo -e "\nimager test ok\n"
echo -e "\nclear tmp files $img $raw $logfile $md5\n"
_ptlbreak
rm -f $img $raw $logfile $md5
